package com.ice.body.hardware.controller;
import com.ice.body.business.model.FaceLogModel;
import com.ice.body.hardware.model.DeviceFace;
import com.ice.body.hardware.service.DeviceFaceService;
import com.ice.body.business.model.WareHouseModel;
import com.ice.body.business.service.WareHouseService;
import com.ice.body.hardware.service.FaceLogService;
import io.swagger.annotations.ApiOperation;
import com.ice.base.controller.BaseController;
import com.github.pagehelper.PageHelper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import com.ice.base.result.ResponseResult;
import com.ice.base.result.AjaxResult;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;

/**
 * Created with GuoYanBin.
 * Description:
 * Date: 2025-11-29
 * Time: 03:17
 */
@RestController
@ApiIgnore(value  = "面部识别")
public class DeviceFaceController extends BaseController{
    //---------------------------面部识别-----------------------start
    @Resource
    private DeviceFaceService deviceFaceService;
    @Resource
    private FaceLogService faceLogService;

 /*
    @ApiOperation(value = "面部识别-新增")
    @PostMapping("/api/DeviceFace/insert")
    public AjaxResult<DeviceFace> insert_DeviceFace(DeviceFace model) {
        AjaxResult r = ResponseResult.success();
        try{
            WareHouseModel wareHouseModel = wareHouseService.selectById(model.getWarehouseId());

            model.setCreateTime(new Date());
            model.setWarehouseName(wareHouseModel.getWarehouseName());

            deviceFaceService.insert(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "面部识别-删除")
    @PostMapping("/api/DeviceFace/deleteById")
    public AjaxResult<DeviceFace> deleteById_DeviceFace(@RequestParam("id") String id) {
        AjaxResult r = ResponseResult.success();
        try{
            deviceFaceService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "面部识别-更新")
    @PostMapping("/api/DeviceFace/updateById")
    public AjaxResult<DeviceFace> update_DeviceFace(DeviceFace model) {
        AjaxResult r = ResponseResult.success();
        try{

            WareHouseModel wareHouseModel = wareHouseService.selectById(model.getWarehouseId());
            model.setWarehouseName(wareHouseModel.getWarehouseName());
            deviceFaceService.update(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "面部识别-查询一个")
    @PostMapping("/api/DeviceFace/selectById")
    public AjaxResult<DeviceFace> selectById_DeviceFace(@RequestParam("id") String id) {
        AjaxResult r = ResponseResult.success();
        try{
           DeviceFace model = deviceFaceService.selectById(id);
           r.setData(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "面部识别-查询多个")
    @PostMapping("/api/DeviceFace/selectAll")
    public AjaxResult<DeviceFace> selectList_DeviceFace(DeviceFace model) {
        AjaxResult r = ResponseResult.success();
        try{
           List<DeviceFace> list = deviceFaceService.selectListByModel(model);
           r.setData(list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @RequiresPermissions("PERMISSION_MENU_MBSB")
    @ApiOperation(value = "面部识别-查询分页")
    @PostMapping("/api/DeviceFace/selectListByPageHelper")
    public AjaxResult<DeviceFace> selectListByPageHelper_DeviceFace(@RequestParam(name = "pageSize") Integer pageSize,
                                                                    @RequestParam(name = "pageNum") Integer pageNum,
                                                                    DeviceFace model,
                                                                    String keyWord){
        AjaxResult r = ResponseResult.success();
        ArrayList list;
        try{
           PageHelper.startPage(pageNum, pageSize);
           if(StringUtils.isEmpty(keyWord)) {
               list = deviceFaceService.selectListByModel(model);
           } else {
               list = deviceFaceService.selectListByKeyWord(keyWord);
           }
           getReturnResultByPage(r,list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }*/

    @PostMapping("/FaceLog/selectFaceLogList")
    public AjaxResult<FaceLogModel> selectFaceLogList(@RequestParam(name = "pageSize") Integer pageSize,
                                                      @RequestParam(name = "pageNum") Integer pageNum,
                                                      FaceLogModel model){
        AjaxResult r = ResponseResult.success();
        ArrayList list;
        try{
           PageHelper.startPage(pageNum, pageSize);

           list = faceLogService.searchFaceLogList(model);

           getReturnResultByPage(r,list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();
        }
        return r;
    }
    //---------------------------面部识别-----------------------end




}
